// 可读性好
#include <bits/stdc++.h>
using namespace std;

void solve(vector<int> &p, int l, int r) {
  if (r - l == 1)
    return;
  int mid = (l + r) / 2;
  int minl = *min_element(p.begin() + l, p.begin() + mid);
  int minr = *min_element(p.begin() + mid, p.begin() + r);
  if (minl > minr)
    reverse(p.begin() + l, p.begin() + r);
  solve(p, l, mid);
  solve(p, mid, r);
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int n = 1 << n;
    vector<int> p(n);
    for (int i = 0; i < n; ++i)
      cin >> p[i];

    solve(p, 0, n);

    for (int i = 0; i < n; ++i)
      cout << p[i] << " \n"[i == n - 1];
  }

  return 0;
}